<?php 
namespace app\api\validate;

use think\Validate;
use app\api\model\SendVerify;

class UserRegisterValidate extends Validate
{
    protected $rule = [
    	'verifyCode'=>'require',
        'mobile'  =>  'require|mobile|unique:user|checkVerifyCode',
        'password' =>  'require',
        
    ];   

    protected $message  =   [
        'mobile.require' => '手机号必须|1',
        'mobile.unique' => '手机号不能重复|2',
        'mobile.mobile'   => '手机号格式不正确|3',
        'verifyCode.require'=>'验证码必须传递|4',
        'mobile.checkVerifyCode'=>'验证码错误或者已失效|5' ,
        'password.require'=>'密码不能为空|6'  
    ];

    public function checkVerifyCode($value, $rule, $data=[])
    {

    	$sendVerify = new SendVerify;
    	$code = $sendVerify->where('mobile',$value)->order('id desc')->find();
    	if(empty($code) || $code->code != $data['verifyCode'] || (time()-strtotime($code->create_time)  > 600*10)){
    		return FALSE;
    	}
    	return TRUE;
    }
   
}


?>